WITH xxx AS comid
// 概览指标：避免笛卡尔积，逐段聚合
OPTIONAL MATCH (n:LAC {group_geo_id: comid})
OPTIONAL MATCH (u:User {group_geo_id: comid})
OPTIONAL MATCH (p:Phone {group_geo_id: comid})
WITH comid, {
  lac_count: count(distinct n),
  user_count: count(distinct u),
  avg_monthly_fee: avg(p.monthly_fee_rmb),
  avg_free_call_minutes: avg(p.free_call_minutes),
  avg_data_allowance_gb: avg(p.data_allowance_gb),
  group_avg_daily_traffic_mb: avg(p.avg_daily_traffic_mb),
  group_avg_domestic_daily_call_min: avg(p.avg_domestic_daily_call_min)
} AS profile

// APP 使用特征：先聚合再 collect，避免“聚合嵌套”
OPTIONAL MATCH (p:Phone {group_geo_id: comid})-[r:use_app]->(end:APP)
WHERE end.app_name IS NOT NULL AND r.online_duration_minutes IS NOT NULL
WITH profile, end.app_name AS appName,
     sum(r.online_duration_minutes) AS totalDuration,
     count(r) AS connectionCount
WITH profile,
     collect({appName: appName, totalDuration: totalDuration, connectionCount: connectionCount}) AS appUsage
RETURN apoc.map.merge(profile, {appUsage: appUsage}) AS profile;